package com.xmall.msg.service.impl;

import com.xmall.msg.queue.CommonModule;
import com.xmall.msg.base.MsgSourceType;
import com.xmall.msg.entity.sys.OperateLogMsg;
import com.xmall.define.request.sys.OperateLogRequest;
import com.xmall.msg.service.ICommonMsgService;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class CommonMsgServiceImpl implements ICommonMsgService {

    @Resource
    private RabbitTemplate rabbitTemplate;

    /**
     * 操作日志消息
     */
    @Override
    public void sendOperateLog(OperateLogRequest operateLogRequest) {
        OperateLogMsg msg = new OperateLogMsg().build(MsgSourceType.COMMON, CommonModule.OperateLog.OPERATE_LOG_DIRECT_EXCHANGE, CommonModule.OperateLog.OPERATE_LOG_ROUTING_KEY).operateLog(operateLogRequest);
        rabbitTemplate.convertAndSend(CommonModule.OperateLog.OPERATE_LOG_DIRECT_EXCHANGE, CommonModule.OperateLog.OPERATE_LOG_ROUTING_KEY, msg, new CorrelationData(msg.getCorrelationKey()));
    }
}
